#ifndef INC_PLANE_H
#define INC_PLANE_H

#include "Vector3.h"
#include "Mathutil.h"

namespace gti
{

class AABB;
class Ray;
class Sphere;

class Plane  
{
public:
	Plane();
	Plane(float a, float b, float c, float d);
	Plane(const vector3f &normal, const vector3f& point);
	Plane(const vector3f& v1,const vector3f& v2,const vector3f& v3);

public:
	void set(const vector3f &normal, const vector3f& point);
	void calculatePlane(const vector3f& v1,const vector3f& v2,const vector3f& v3);

	// normalize the plane
	void normalize();

// precise overlap tests

	// plane aabb overlap test
	CullFlag overlap(const AABB &box) const;
	// plane sphere overlap test
	CullFlag overlap(const Sphere &sphere) const;

// useful methods
	// return the distance from the point to the plane
	float getDistance(const vector3f& point) const;

	void getClosestPoint(const vector3f& point, vector3f& closest) const;

	// returns the corners nearest and farest from the plane 
	void getNearAndFarPoints(const AABB& box, vector3f& vmin,vector3f& vmax) const;

// render methods
	
	void render(float size = 5) const;
	void renderWire(float size = 5) const;

public:
	vector3f n;
	float d;
};

};//namespace gti

#endif//INC_PLANE_H
